package com.atguigu.service.impl;

import com.atguigu.entity.ProductSalePropertyKey;
import com.atguigu.entity.ProductSalePropertyValue;
import com.atguigu.mapper.ProductSalePropertyValueMapper;
import com.atguigu.service.ProductSalePropertyValueService;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Decoder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * spu销售属性值 服务实现类
 * </p>
 *
 * @author linjiang
 * @since 2022-07-24
 */
@Service
public class ProductSalePropertyValueServiceImpl extends ServiceImpl<ProductSalePropertyValueMapper, ProductSalePropertyValue> implements ProductSalePropertyValueService {


    @Override
    public Map<Object, Object> getSalePropertyIdAndSkuIdMapping(Long productId) {
        //冲数据库理查数据
          List<Map> salePropertyIdAndSkuIdMap=baseMapper.getSalePropertyIdAndSkuIdMapping(productId);

        //根据需要的数据格式返回
        Map<Object, Object> mapResult = new HashMap<>();
        for (Map map : salePropertyIdAndSkuIdMap) {
            mapResult.put(map.get("sale_property_value_id"),map.get("sku_id"));
        }
        return mapResult;
    }

    @Override
    public List<ProductSalePropertyKey> getSpuSalePropertyAndSelected(Long productId, Long skuId) {
      return   baseMapper.getSpuSalePropertyAndSelected(productId,skuId);
    }
}
